@extends('../layouts.base')  

@section('content')
<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
		<span class="c-gray en">&gt;</span>
		产品管理
		<span class="c-gray en">&gt;</span>
		订单管理 <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
	<div class="Hui-article">
		<article class="cl pd-20">
			
			<div>
				<form method="get" action="/product/order/index">
					订单编号:<input type="text" class="input-text" style="width:120px" placeholder="输入订单编号" id="order_num" name="order_num">
					
					状态:<span class="select-box" style="width: 120px;">
					  <select class="select" size="1" name="status">
					  	<option value="">全部</option>
					  	<option value="0">待付款</option>
					  	<option value="1">已付款</option>
					  	<option value="2">检测中</option>
					  	<option value="3">已上传报告</option>
					  	<option value="4">待评价</option>
					  	<option value="5">已评价</option>
					  	<option value="6">已取消</option>	
					  </select>
					</span>
					
					 日期范围：
					<input name="start_time" type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
					-
					<input name="end_time" type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;">
					
					<button type="submit" class="btn btn-primary" id="" name=""><i class="Hui-iconfont">&#xe665;</i>搜索</button>
				</form>
			</div>
			<div class="mt-20">
				
			</div>
			<table id="table" class="table table-border table-bordered table-bg" current_page="{{$data['data']->currentPage()}}">
				<thead>
					<tr>
						<th scope="col" colspan="8">订单列表</th>
					</tr>
					<tr class="text-c">
						<th width="25"><input type="checkbox" name="" value=""></th>
						<th width="40">ID</th>
						<th width="150">订单编号</th>
						<th width="150">支付金额</th>
						<th width="80">状态</th>
						<th width="150">收获地址</th>
						<th width="150">下单时间</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<tbody>
					
					@if($data['code'] == 1)		
					@foreach ($data['data'] as $item)
						<tr class="text-c">
							<td><input type="checkbox" value="1" name=""></td>
							<td>{{$item->id}}</td>
							<td>{{$item->order_num}}</td>
							<td>{{$item->total_price}}</td>
							<td class="td-updown">
								@if($item->status === 0)
									<span class="c-primary">待付款</span>
								@elseif($item->status === 1)
									<span class="c-blue">已付款</span>
								@elseif($item->status === 2)
									<span class="c-success">检测中</span>
								@elseif($item->status === 3)
									<span class="c-error">报告已上传</span>
								@elseif($item->status === 4)
									<span class="c-warning">待评价</span>
								@elseif($item->status === 5)
									<span class="c-green">已评价</span>
								@elseif($item->status === 6)
									<span class="c-orange">已取消</span>
								@else
									<span class="c-black">未知状态</span>
								@endif
							</td>
							<td>{{$item->address_text}}</td>
							<td>{{$item->created_at}}</td>
							<td class="td-manage">
								<a class='btn btn-secondary size-MINI' href="/product/order/detail?id={{$item->id}}" title="详情">详情</a>
								@if ($item->status === 0)										
								@elseif($item->status === 1)
   									<a class='btn btn-success size-MINI detection' data-id="{{$item->id}}" data-status="2" href="javascript:;" title="检测">置位检测</a>
								@elseif($item->status === 2)
									<a class='btn btn-warning size-MINI uploadBook' data-id="{{$item->id}}" data-status="3" href="javascript:;" title="上传报告">上传报告</a>	
								@elseif($item->status === 3)
								@elseif($item->status === 4)
									
								@elseif($item->status === 5)	
									<a class='btn btn-default size-MINI lookComment' data-id="{{$item->id}}" href="/product/comment/detail?oid={{$item->id}}" title="查看评价">查看评价</a>	
								@elseif($item->status === 6)
									<a title="删除" href="javascript:;" onclick="admin_del(this,{{$item->id}},'/product/order/delete','/product/order/index')" class="btn btn-danger size-MINI" style="text-decoration:none">删除</a>
								@else
								@endif
							
						
							</td>
						</tr>
					@endforeach	
									
					@else
						<tr>
							<td colspan="8" style="text-align: center;">{{$data['msg']}}</td>
						</tr>
					@endif					
					
					
				</tbody>
			</table>
		
			@if($data['data']->hasPages())
				<tfoot>
					<tr>
						<th colspan="8">
							{{ $data['data']->appends(request()->all())->links() }}
						</th>
					</tr>
				</tfoot>
			@endif
		</article>
	</div>
</section>

<div style="display: none;">
 	<input type="file" name="file" class="input-file" id="file_book">
 	<input type="hidden"  id="oid" value="">
</div>
 
@endsection




@section('script')
<script type="text/javascript" src="/HadminPage/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="/HadminPage/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="/HadminPage/lib/laypage/1.2/laypage.js"></script> 
	
<script type="text/javascript">

//设置为检测中
$('.detection').click(function(){
	var id     = $(this).attr('data-id')
	var status = $(this).attr('data-status');
	var current_page = $("table[id='table']").attr('current_page')
	var status_url   = '/product/order/status';
	var jump_url     = '/product/order/index'
	$.ajax({
		type: 'POST',
		url: status_url,
		data:{id:id,status:status,_token: $('meta[name="token"]').attr('token')},
		dataType: 'json',
		success: function(res){				
			if(res.code == 1){
				window.location.href=jump_url+'?page='+current_page
			}else{
				layer.msg(res.msg);
			}
		},
		error:function(res) {
			layer.msg(res.msg);
		},
	});		
});

$('.uploadBook').click(function(e){
	 e.preventDefault();
	 var oid = $(this).attr('data-id')
	 $('#oid').val(oid)
	 $('#file_book').click();
})

$('#file_book').change(function(){
	var current_page = $("table[id='table']").attr('current_page')
	var jump_url     = '/product/order/index'
	var upload_url = '/product/order/upload';
		
		var formData = new FormData();
		formData.append("file", document.getElementById("file_book").files[0]);
		formData.append("oid", document.getElementById("oid").value);
		$.ajax({
			url: upload_url,
			type: 'post',
			data: formData,
			headers: {
	            'X-CSRF-TOKEN': $('meta[name="token"]').attr('token'),
	        },
			cache: false,
			/**
			*必须false才会自动加上正确的Content-Type
			*/
			contentType: false,
			/**
			* 必须false才会避开jQuery对 formdata 的默认处理
			* XMLHttpRequest会对 formdata 进行正确的处理
			*/
			processData: false,
			success: function (res) {
				if(res.code == 1){
					window.location.href=jump_url+'?page='+current_page
				}else{
					layer.msg(res.msg);
				}
			    console.log(res,66666)
			},
			error:function(res) {
				layer.msg(res.msg);
			},
		})
	});
</script> 
@endsection







